package com.sunjob.mrotech.server.Impl;

import com.sunjob.common.domain.tech.Fault;
import com.sunjob.common.result.Result;
import com.sunjob.common.util.MROUtils;
import com.sunjob.mrotech.mapper.FaultMapper;
import com.sunjob.mrotech.server.FaultServer;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Author tlj
 * @Date 2022/8/8 8:17
 * @PackageName:com.sunjob.mrotech.server.Impl
 * @ClassName: FaultServerImpl
 * @Description: TODO
 * @Version 1.0
 */
@Service
@Slf4j
public class FaultServerImpl implements FaultServer {
    @Autowired
    FaultMapper mapper;

    @Override
    public Result faultqueryall(String fault_phenomenon) {
        List<Fault> fault = mapper.faultqueryall(fault_phenomenon);
        if (fault.size()<0){
            return Result.fail("没有此故障哦");
        }
        return Result.ok(fault,"查询成功");
    }

    @Override
    public Result insertfault(Fault fault) {
        fault.setId(MROUtils.nextId());
        int insert = mapper.insertfault(fault);
        if (insert>0){
            return Result.ok(null,"新增失败");
        }
        return Result.fail("新增失败");
    }

    @Override
    public Result selectfault(String configuration_id) {
        List<Fault> sel = mapper.selectfault(configuration_id);
        if (sel.size()<0){
          return   Result.fail("查询失败，此构型还没有故障字典，请先新增");
        }
        return Result.ok(sel,"查询成功");
    }

    @Override
    public Result upfault(Fault fault) {
        int up = mapper.upfault(fault);
        if (up>0){
            return Result.ok(null,"修改成功");
        }
        return Result.fail("修改失败");
    }

    @Override
    public Result delfault(Long id) {
        int del = mapper.delfault(id);
        if (del>0){
            return Result.ok(null,"删除成功");
        }
        return Result.fail("没有这个id，删除失败");
    }

    @Override
    public Result cxfault(Long id) {
        Fault fault = mapper.cxfault(id);
        if (fault!=null){
            return Result.ok(fault,"查询成功");
        }
        return Result.fail("查询失败");
    }
}
